import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
summary
모든 노드가 동일한 degree를 갖는 그래프, degree matrix가 \(I\)나 \(kI\)로 나타낼 수 있는 그래프
degree matrix: the degree matrix of an undirected graph is a diagonal matrix which contains information about the degree of each vertex—that is, the number of edges attached to each vertex.
Import
Regular Graph
definition of wiki: each vertex has the same number of neighbors; i.e. every vertex has the same degree or valency.
모든 node가 동일한 degree를 갖는 그래프
Tip for future work
이것은 시계열에서의 Graph Shift Operator로써 볼 수 있지.1
1 단, 단위행렬일때, 단위행렬의 배수가 아니라.
=np.zeros((5,5))
wfor i in range(5):
for j in range(5):
if i==j :
= 0
w[i,j] elif i-j == 1 :
= 1
w[i,j] elif j-i == 4 :
= 1 w[i,j]
w
array([[0., 0., 0., 0., 1.],
[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.]])
= []
lst for i in range(5):
for j in range(5):
if w[i,j] == 1:
lst.append([i,j])
np.array(lst)
array([[0, 4],
[1, 0],
[2, 1],
[3, 2],
[4, 3]])
동일한 차수를 갖는다?
참고로, 무조건 degree matrix가 단위행렬일 필요는 없고 \(D = kI\)가 성립해도 Regular Graph
= w.sum(axis=1)
d= np.diag(d) D
D
array([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
= nx.Graph() G
G.add_edges_from(np.array(lst))
=(10, 10))
plt.figure(figsize=True, font_weight='bold', node_color='orange', node_size=1500, font_color='white', font_size=30,width=5) nx.draw_networkx(G, with_labels
Non-Regular Graph
= np.array([[0., 0., 0., 0., 0.],
w 1., 0., 1., 1., 1.],
[1., 1., 0., 0., 1.],
[0., 0., 1., 0., 1.],
[0., 0., 0., 0., 0.]]) [
= []
lst for i in range(5):
for j in range(5):
if w[i,j] == 1:
lst.append([i,j])
np.array(lst)
array([[1, 0],
[1, 2],
[1, 3],
[1, 4],
[2, 0],
[2, 1],
[2, 4],
[3, 2],
[3, 4]])
모든 Degree가 동일하는 가정이 무너져 regular graph 로 정의할 수 없음
= w.sum(axis=1)
d= np.diag(d) D
D
array([[0., 0., 0., 0., 0.],
[0., 4., 0., 0., 0.],
[0., 0., 3., 0., 0.],
[0., 0., 0., 2., 0.],
[0., 0., 0., 0., 0.]])
= nx.Graph() G
G.add_edges_from(np.array(lst))
=(10, 10))
plt.figure(figsize=True, font_weight='bold', node_color='orange', node_size=1500, font_color='white', font_size=30,width=5) nx.draw_networkx(G, with_labels
Several Types of regular graph
0-regular graph
참고 아래도 동일 차수이므로 regular graph
= np.array([[1., 0., 0., 0., 0.],
w 0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]]) [
= w.sum(axis=1)
d= np.diag(d) D
Degree matrix = \(I\)
D
array([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
= []
lst for i in range(5):
for j in range(5):
if w[i,j] == 1:
lst.append([i,j])
= nx.Graph() G
G.add_edges_from(np.array(lst))
=(10, 10))
plt.figure(figsize=True, font_weight='bold', node_color='orange', node_size=1500, font_color='white', font_size=30,width=5) nx.draw_networkx(G, with_labels
1-regular graph
= np.array([
w 0., 1., 0., 0., 0., 0.],
[1., 0., 0., 0., 0., 0.],
[0., 0., 0., 1., 0., 0.],
[0., 0., 1., 0., 0., 0.],
[0., 0., 0., 0., 0., 1.],
[0., 0., 0., 0., 1., 0.]]) [
= w.sum(axis=1)
d= np.diag(d) D
Degree matrix = \(I\)
D
array([[1., 0., 0., 0., 0., 0.],
[0., 1., 0., 0., 0., 0.],
[0., 0., 1., 0., 0., 0.],
[0., 0., 0., 1., 0., 0.],
[0., 0., 0., 0., 1., 0.],
[0., 0., 0., 0., 0., 1.]])
= []
lst for i in range(6):
for j in range(6):
if w[i,j] == 1:
lst.append([i,j])
= nx.Graph() G
G.add_edges_from(np.array(lst))
=(10, 10))
plt.figure(figsize=True, font_weight='bold', node_color='orange', node_size=1500, font_color='white', font_size=30,width=5) nx.draw_networkx(G, with_labels
2-regular graph
= np.array([
w 0., 1., 1., 0., 0., 0.],
[1., 0., 1., 0., 0., 0.],
[1., 1., 0., 0., 0., 0.],
[0., 0., 0., 0., 1., 1.],
[0., 0., 0., 1., 0., 1.],
[0., 0., 0., 1., 1., 0.]]) [
= w.sum(axis=1)
d= np.diag(d) D
Degree matrix = \(2I\)
D
array([[2., 0., 0., 0., 0., 0.],
[0., 2., 0., 0., 0., 0.],
[0., 0., 2., 0., 0., 0.],
[0., 0., 0., 2., 0., 0.],
[0., 0., 0., 0., 2., 0.],
[0., 0., 0., 0., 0., 2.]])
= []
lst for i in range(6):
for j in range(6):
if w[i,j] == 1:
lst.append([i,j])
= nx.Graph() G
G.add_edges_from(np.array(lst))
=(10, 10))
plt.figure(figsize=True, font_weight='bold', node_color='orange', node_size=1500, font_color='white', font_size=30,width=5) nx.draw_networkx(G, with_labels
3-regular graph
= np.array([
w 0., 1., 1., 0., 0., 1.],
[1., 0., 1., 1., 0., 0.],
[1., 1., 0., 0., 1., 0.],
[0., 1., 0., 0., 1., 1.],
[0., 0., 1., 1., 0., 1.],
[1., 0., 0., 1., 1., 0.]]) [
= w.sum(axis=1)
d= np.diag(d) D
Degree matrix = \(3I\)
D
array([[3., 0., 0., 0., 0., 0.],
[0., 3., 0., 0., 0., 0.],
[0., 0., 3., 0., 0., 0.],
[0., 0., 0., 3., 0., 0.],
[0., 0., 0., 0., 3., 0.],
[0., 0., 0., 0., 0., 3.]])
= []
lst for i in range(6):
for j in range(6):
if w[i,j] == 1:
lst.append([i,j])
= nx.Graph() G
G.add_edges_from(np.array(lst))
=(10, 10))
plt.figure(figsize=True, font_weight='bold', node_color='orange', node_size=1500, font_color='white', font_size=30,width=5) nx.draw_networkx(G, with_labels